package ui;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JPanel;


public class Grille extends JPanel {
	
	private int tailleGrille;
	private String arbres[][] = {null};

	public String[][] getArbres() {
		return arbres;
	}

	public void setArbres(String[][] arbres) {
		this.arbres = arbres;
	}

	public int getTailleGrille() {
		return tailleGrille;
	}

	public void setTailleGrille(int tailleGrille) {
		this.tailleGrille = tailleGrille;
	}

	public Dimension getPreferredSize() {
        return new Dimension(550,550);
    }
	
	public void paintComponent(Graphics g) {
        super.paintComponent(g);       

      //dessin colonne
		for (int i = 0; i <= tailleGrille*10; i=i+10) {
			g.drawLine(i, 0, i, tailleGrille*10);
		}
		//dessin ligne
		for (int i = 0; i <= tailleGrille*10; i=i+10) {

			g.drawLine(0, i, tailleGrille*10, i);

		}
		

		for (int i = 0; i < tailleGrille; i++) {
			g.setColor(new Color(51, 51, 51) );
			g.fillRect(1, (i*10)+1, 9, 9);
			g.fillRect((tailleGrille*10)-9, (i*10)+1, 9, 9);
			g.fillRect((i*10)+1, (tailleGrille*10)-9, 9, 9);
			g.fillRect((i*10)+1, 1, 9, 9);
			
		}

		
		
			for (int i = 1; i < tailleGrille-1; i++) {
				for (int j = 1; j < tailleGrille-1; j++) {
					if (arbres[i][j]=="jeune_pousse"){
						g.setColor(new Color(154, 205, 50) );
						g.fillRect((i*10)+1, (j*10)+1, 9, 9);
					}
					else if (arbres[i][j]=="arbuste"){
						g.setColor(new Color(50, 148, 68) );
						g.fillRect((i*10)+1, (j*10)+1, 9, 9);
					}
					else if (arbres[i][j]=="arbuste2"){
						g.setColor(new Color(50, 148, 68));
						g.fillRect((i*10)+1, (j*10)+1, 9, 9);
					}
					else if (arbres[i][j]=="arbre"){
						g.setColor(new Color(29, 71, 33));
						g.fillRect((i*10)+1, (j*10)+1, 9, 9);
					}
					else if(arbres[i][j]=="feu"){
						g.setColor(new Color(238, 31, 37));
						g.fillRect((i*10)+1, (j*10)+1, 9, 9);
					}
					else if(arbres[i][j]=="cendre"){
						g.setColor(new Color(129, 130, 129));
						g.fillRect((i*10)+1, (j*10)+1, 9, 9);
					}
					else if(arbres[i][j]=="insecte"){
						g.setColor(new Color(109, 58, 150));
						g.fillRect((i*10)+1, (j*10)+1, 9, 9);
					}
					else{
						g.setColor(Color.white);
						g.fillRect((i*10)+1, (j*10)+1, 9, 9);
					}

				}
			}
    } 

}
